package com.dz.control;

import com.dz.bean.role;
import com.dz.dao.roleMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.models.auth.In;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class roleControl {

    @Resource
    private roleMapper roleMapper;

    @ResponseBody
    @RequestMapping("getroleAll")
    public List<role> getrole(){

       List<role> list= roleMapper.selectAll();
       return list;
    }
    @ResponseBody
    @RequestMapping("getroleAll01")
    public PageInfo getrole01(Model model, @RequestParam(defaultValue = "1",value = "pageNum") Integer pageNum){
        PageHelper.startPage(pageNum,5);
        List<role> list= roleMapper.selectAll();
        PageInfo<role> pageInfo = new PageInfo<>(list);

        model.addAttribute("pageInfo",pageInfo);


        return pageInfo;
    }

    @ResponseBody
    @RequestMapping("getroleInsert")
    public int  insertrole(HttpServletRequest request){
        role r1 =new role();
        String rname=request.getParameter("rname");
        String rguize=request.getParameter("rguize");
        String miaoshu=request.getParameter("miaoshu");
        r1.setRname(rname);
        r1.setRguize(rguize);
        r1.setMiaoshu(miaoshu);
        int i= roleMapper.roleinsert(r1);
        return i;


    }

    @ResponseBody
    @RequestMapping("deleterolr")
    public int  deleterole(HttpServletRequest request){
       String strid= request.getParameter("id");
       int id= Integer.valueOf(strid);

        int i= roleMapper.deleteRole(id);
        return i;


    }

    @RequestMapping("role-add")
    public String role(){

        return "role-add";
    }

}
